import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:material_collection_app/utils/color.dart';
import 'package:material_collection_app/widget/common/underline_indicator.dart';

class TabBarCustomReturn extends StatelessWidget {
  final List tabs;
  final EdgeInsets indicatorInsets;
  final bool buildTab;

  TabBarCustomReturn({
    Key key,
    @required this.tabs,
    this.indicatorInsets = const EdgeInsets.fromLTRB(19, 0, 19, 0),
    this.buildTab = false
  })
  : super(key: key);
  
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: false);

    Widget _buildTab(title) {
      return Tab(
        child: Container(
          alignment: Alignment.center,
          width: 120.w,
          child: Text(title),
        )
      );
    }

    return Theme(
      data: ThemeData(
        splashColor: Colors.transparent,
        highlightColor: Colors.transparent,
        primarySwatch: createMaterialColor(Color(0xFFeeeeee)),
        primaryColor: Colors.blue,
      ),
      child: Stack(
        children: <Widget>[
          InkWell(
            onTap: () {
              Navigator.pop(context);
            },
            child: Padding(
              padding: EdgeInsets.fromLTRB(25.w, 35.w, 25.w, 35.w),
              child: Image.asset('assets/arrow_return.png', width: 17.w,)
            ),
          ),
          Align(
            alignment: Alignment.center,
            child: TabBar(
              indicator: UnderlineIndicator(
                insets: indicatorInsets
              ),
              labelPadding: EdgeInsets.symmetric(horizontal: 20.w), // label内边距
              isScrollable: true,
              indicatorSize: TabBarIndicatorSize.label,
              unselectedLabelColor: Colors.white,
              labelStyle: TextStyle( //选中文字样式
                fontSize: 36.w, 
                fontWeight: FontWeight.bold
              ), 
              unselectedLabelStyle: TextStyle( //未选中文字样式
                fontSize: 14, fontWeight: FontWeight.w500
              ),
              // tabs: tabs.map((text) => _buildTab(text)).toList(),
              tabs: buildTab ? 
                tabs.map((text) => _buildTab(text)).toList() : 
                tabs.map((text) => Tab(text: text)).toList(),
            )
          )
        ]
      )
    );
  }
}